package com.amc.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.amc.dao.IMerchantDao;
import com.amc.dto.FoodView;
import com.amc.entity.FoodType;
import com.amc.entity.Merchant;
import com.amc.service.IMerchantService;
import com.amc.utils.AdvertismentRequest;
import com.amc.utils.MerchantListRequest;


@Service(value = "merchantService")
public class MerchantServiceImpl implements IMerchantService {

	private IMerchantDao dao;

	@Resource
	public void setDao(IMerchantDao dao) {
		this.dao = dao;
	}

	@Override
	@Transactional
	public List<Merchant> queryAllMerchants(List<String> merchantsId) {
		return dao.queryAllMerchants(merchantsId);
	}

	@Override
	@Transactional
	public List<Merchant> queryMerchantByFoodType(String foodType,
			List<Merchant> merchants) {
		List<Merchant> mers= dao.queryMerchantByFoodType(foodType);
		List<Merchant> results = new ArrayList<>();
		for (Merchant m : mers) {
			if (merchants.contains(m)) {
				results.add(m);
			}
		}
		return results;
	}

	@Override
	@Transactional
	public List<Merchant> queryMerchants(String keyWord) {
		return dao.queryMerchants(keyWord);
	}

	@Override
	@Transactional
	public List<String> requestMerchantsId() {
		MerchantListRequest mr=new MerchantListRequest();
		return mr.MerchantRequest();
	}

	@Override
	@Transactional
	public List<FoodView> requestAdv() {
		List<String> advId = AdvertismentRequest.advertimentRequest();
		List<FoodView> foodsView = dao.queryFood(advId);
		if(foodsView == null || foodsView.size() == 0)
			foodsView.add(new FoodView(null, null, "Test", 28.88, "https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1502867039&di=db37d70d56ddb6624d0d2c62020c28f8&src=http://pic3.16pic.com/00/00/02/16pic_2024_b.jpg", "", 1L));
		return foodsView;
	}
	
	@Override
	@Transactional
	public List<FoodType> queryFoodTypeByMerchantList(List<Merchant> merchants) {
		return dao.queryFoodTypeByMerchantList(merchants);
	}

	@Override
	@Transactional
	public List<FoodView> queryFood(List<String> advId) {
		return dao.queryFood(advId);
	}

	@Override
	public double calculateSore(String merchantId) {
		// TODO Auto-generated method stub
		return dao.calculateSore(merchantId);
	}
	
}
